/*
 * GameMap.cpp
 *
 *  Created on: 16.04.2012
 *      Author: Caffeine
 */




#include "GameMap.h"

#include "../log/Log.h"

GameMap::GameMap(irr::IrrlichtDevice*d){
	if (!d){
		LOGE("IrrlichtDevice=null");
		return;
	}
	smgr=d->getSceneManager();
	selector=smgr->createMetaTriangleSelector();
}

void GameMap::addToCollision(irr::scene::IAnimatedMeshSceneNode*node,bool Triangle){
	irr::scene::ITriangleSelector*ts=0;
	if (Triangle)
		ts=smgr->createTriangleSelector(node);
	else
		ts=smgr->createTriangleSelectorFromBoundingBox(node);
	node->setTriangleSelector(ts);
	addToCollision(ts);
	ts->drop();
}

void GameMap::addToCollision(irr::scene::ITriangleSelector*ts){
	selector->addTriangleSelector(ts);
}

GameMap::~GameMap(){
	selector->drop();
}

irr::scene::IMetaTriangleSelector*GameMap::getSelector(){
	return selector;
}

void GameMap::removeFromCollision(irr::scene::ISceneNode*ts){
	if (ts->getChildren().size()>0){
		irr::core::list<irr::scene::ISceneNode*>::ConstIterator t=ts->getChildren().begin();
		do{
			removeFromCollision(*t);
			t++;
		}while (t!=ts->getChildren().end());
	}
	removeFromCollision(ts->getTriangleSelector());
}

void GameMap::removeFromCollision(irr::scene::ITriangleSelector*ts){
	if (ts)
		selector->removeTriangleSelector(ts);
}
/*
bool GameMap::getHeight(irr::f32 X,irr::f32 Z,irr::f32*pos){
	CALL_FUN;
	return false;
}

bool GameMap::getHeight(irr::core::vector3df p,irr::f32*pos){
	CALL_FUN;
	return false;
}

bool GameMap::getHeightEx(irr::core::vector3df p,irr::f32*pos){
	CALL_FUN;
	return false;
}
*/
